package com.pearadmin.pro.modules.ta.rest;

import cn.hutool.core.clone.Cloneable;
import com.mchange.v2.codegen.bean.CloneableExtension;
import com.pearadmin.pro.common.aop.annotation.Log;
import com.pearadmin.pro.common.constant.ControllerConstant;
import com.pearadmin.pro.common.tools.core.ExcelUtil;
import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.domain.Result;
import com.pearadmin.pro.modules.ta.domain.TA;
import com.pearadmin.pro.modules.ta.dto.TaDTO;
import com.pearadmin.pro.modules.ta.dto.TaExcelImportDTO;
import com.pearadmin.pro.modules.ta.param.TARequest;
import com.pearadmin.pro.modules.ta.service.TAService;
import com.pearadmin.pro.modules.ta.vo.TaVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.utils.CloneUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * taController
 *
 * @author ChenJian
 * @date 2021-08-22
 */
@Api(tags = {"ta"})
@RestController
@RequestMapping(ControllerConstant.ADMIN+"ta/tA")
@Slf4j
public class TAController extends BaseController
{
    @Resource
    private TAService tAService;

    @PostMapping("/importTa")
    @Log(title = "ta导入")
    @ApiOperation(value = "ta导入")
    public Result importTa(HttpServletRequest response,@RequestParam("file") MultipartFile file){
        log.info("dd:ddddddddddddddddddddddddddddddddddddddddd");
        List<TaExcelImportDTO> taList = ExcelUtil.read(response, TaExcelImportDTO.class);
        log.info("dd:{}",taList.size());
        return success();
    }


    /**
     * 查询ta列表
     *  @param request 查询参数
     *  @return {@link Result}
     */
    @GetMapping("/page")
    @Log(title = "ta列表")
    @ApiOperation(value = "ta列表")
    public Result<TaVo> list(TARequest tARequest)
    {
        return success(tAService.page(tARequest));
    }


    /**
     * 新增保存ta
     * @param tA 查询参数
     * @return {@link Result}
     */
    @PostMapping("/save")
    @Log(title = "新增ta")
    @ApiOperation( "新增ta")
    public Result save(@RequestBody TaDTO tA)
    {
        return auto(tAService.saveOrUpdate(tA));
    }

    /**
     * 查询ta详情
     *
     * @param id taID
     * @return ta
     */
    @GetMapping("/selectById")
    @Log(title = "查询ta详情")
    @ApiOperation(value = "查询ta详情")
    public Result<TaDTO> selectById(@RequestParam Long id)
    {
        return success(tAService.selectTAById(id));
    }



    /**
     * 修改保存ta
     * @param tA 查询参数
     * @return {@link Result}
     */
    @PutMapping("/update")
    @Log(title = "修改ta")
    @ApiOperation(value = "修改ta")
    public Result update(@RequestBody TaDTO tA)
    {
        return auto(tAService.saveOrUpdate(tA));
    }


    /**
     * 删除保存ta
     * @param id 查询参数
     * @return {@link Result}
     */
    @DeleteMapping("/remove")
    @Log(title = "删除ta")
    @ApiOperation(value = "删除ta")
    public Result remove(@RequestParam Long id)
    {
        return auto(tAService.removeById(id));
    }

    /**
    * 批量删除ta
    * @param ids 批量删除
    * @return {@link Result}
    */
    @DeleteMapping("removeBatch")
    @Log(title = "批量删除ta")
    @ApiOperation(value = "批量删除ta")
    public Result removeBatch(@RequestParam List<Long> ids){
        return auto(tAService.removeByIds(ids));
    }

}
